//
//  ShareView.m
//  Cat
//
//  Created by lushitong on 2018/12/18.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "ShareView.h"
#import "ShareImageView.h"
#import "QKShareLiveSheetManager.h"
#import "ShareManager.h"
#import "ShareManager.h"
#import "FMDBUser.h"
#import "UserInfoManager.h"
#import "FLTool.h"

@interface ShareView()

@property (nonatomic, strong) ShareImageView *shareQQView;
@property (nonatomic, strong) ShareImageView *shareWeChatcView;

@property (nonatomic, strong) UILabel *bottomInfoLabel;
@property (nonatomic, strong) NSString *shareURl;

@end

@implementation ShareView

+ (CGSize)getShareSize {
	return CGSizeMake(ScreenWidth, kQKFitModuleDecimal(375));
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		self.backgroundColor = [UIColor whiteColor];
		[self loadAllSubView];
	}
	return self;
}

- (void)loadAllSubView {
	[self addSubviews:@[self.bottomInfoLabel,
						self.shareQQView,
						self.shareWeChatcView]];
	
	[self.shareWeChatcView  mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo([ShareImageView getSize]);
		make.top.equalTo(self.mas_top).offset(kQKFitModuleDecimal(48));
		make.left.equalTo(self.mas_left).offset((ScreenWidth / 2 + kQKFitModuleDecimal(40.0)));
	}];
	
	[self.shareQQView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo([ShareImageView getSize]);
		make.top.equalTo(self.mas_top).offset(kQKFitModuleDecimal(48));
		make.right.equalTo(self.mas_right).offset(-(ScreenWidth / 2 + kQKFitModuleDecimal(40.0)));
	}];
	
	[self.bottomInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.bottom.equalTo(self.mas_bottom).offset(-kQKFitModuleDecimal(16));
		make.centerX.equalTo(self.mas_centerX);
	}];
}

- (void)dissMissSheet {
	[QKShareLiveSheetManager dismissPlayList];
}

- (void)shareAction {
	[ShareManager shareWebPageToPlatformType:UMSocialPlatformType_QQ andWith:self.currentViewController];
}

#pragma mark----- lazy init -----

- (UILabel *)bottomInfoLabel {
	if (!_bottomInfoLabel) {
		_bottomInfoLabel = [UILabel labelWithText:@"分享到微信/QQ/自动复制链接" font:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _bottomInfoLabel;
}

- (void)clickWithType:(UMSocialPlatformType)platformType {
	FMDBUser *user = [UserInfoManager userWithPhone:UDPhone];
	NSString *shareURL = [NSString stringWithFormat:@"%@/html/invite.html?phone=%@&invite=%@&avatar=%@",SHARE_HOST,UDPhone,user.inviteCode,user.avator];
	if (platformType == UMSocialPlatformType_QQ || platformType == UMSocialPlatformType_WechatSession ) {
		[ShareManager shareWebPageToPlatformType:platformType withShareUrL:shareURL andWith:self.currentViewController];
	}
}

- (ShareImageView *)shareQQView {
	if (!_shareQQView) {
		_shareQQView = [[ShareImageView alloc] init];
		[_shareQQView setShareImageName:@"me_share_qq_pic" andShareTitle:@"QQ"];
		[_shareQQView clickShareButton:^{
			[self clickWithType:UMSocialPlatformType_QQ];
		}];
	}
	return _shareQQView;
}

- (ShareImageView *)shareWeChatcView {
	if (!_shareWeChatcView) {
		_shareWeChatcView = [[ShareImageView alloc] init];
		[_shareWeChatcView setShareImageName:@"me_share_wechat_pic" andShareTitle:@"微信"];
		[_shareWeChatcView clickShareButton:^{
			[self clickWithType:UMSocialPlatformType_WechatSession];
		}];
	}
	return _shareWeChatcView;
}

@end
